package com.yz.lzq.liwushuo.ui.modules.home.boutique.gridview.creditstopic;

import com.yz.lzq.liwushuo.http.HttpUtils;
import com.yz.lzq.liwushuo.http.OnGetNetDataListener;
import com.yz.lzq.liwushuo.jsonbean.home.boutique.creditstopic.CreditsTopicBean;

import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2016/12/22.
 */

public class CreditsTopicModel implements CreditsTopicContract.CreditsTopicModelInterface {
    @Override
    public void getDetaildeInformation(int itemID, String currentItemId, final OnGetNetDataListener<String[]> listener) {

        String strings = null;
        if (itemID == 0) {
            strings = currentItemId;
        } else {
            strings = itemID + "";
        }
        Observable<CreditsTopicBean> observable = HttpUtils.getInstance().getIApi().getCreditsTopicBean(strings);
        observable
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<CreditsTopicBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.onGetDataFalied(e);
                    }

                    @Override
                    public void onNext(CreditsTopicBean creditsTopicBean) {
                        listener.onGetDataSucess(new String[]{creditsTopicBean.getData().getLikes_count() + "", creditsTopicBean.getData().getShares_count() + "", creditsTopicBean.getData().getComments_count() + "", creditsTopicBean.getData().getUrl()});
                    }
                });
    }
}
